/**
 * @author wcj
 * @Date 2021/6/6 9:57
 * @Version 1.0
 */
public class DeadLockTest {

    private static String A = "A";
    private static String B = "B";

    public static void deadLock() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (A) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (B) {
                        System.out.println("我需要B");
                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (B) {
                    synchronized (A) {
                        System.out.println("我需要A");
                    }
                }
            }
        }).start();
    }

    public static void main(String[] args) {
        deadLock();
    }
}
